/*
 * @Author: “ygnnli” “1585923072@qq.com”
 * @Date: 2024-08-01 15:41:04
 * @LastEditors: “ygnnli” “1585923072@qq.com”
 * @LastEditTime: 2024-08-02 16:55:28
 * @FilePath: /110/LockGuard.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#ifndef __LOCK_GUARD_HPP__
#define __LOCK_GUARD_HPP__

#include <iostream>
#include <pthread.h>

// 锁
class LockGuard
{
public:
    // 构造函数加锁
    LockGuard(pthread_mutex_t *mutex)
        : m_mutex(mutex)
    {
        pthread_mutex_lock(m_mutex);
    }
    // 析构函数解锁
    ~LockGuard()
    {
        pthread_mutex_unlock(m_mutex);
    }

private:
    pthread_mutex_t *m_mutex;
};

#endif